<?php
/**
 * Prado Portal.
 *
 * @author Steen Rabol <steen.rabol@gmail.com>
 * @link http://www.pradoportal.dk/
 * @copyright Copyright &copy; 2006,2007,2008 Steen Rabol
 * @license http://www.pradoportal.dk
 * @version $Id: DeleteUser.php 321 2008-11-23 07:45:20Z steen.rabol@gmail.com $
 *
 */

class DeleteUser extends PortalSystemPage
{
	private $_userRecord = null;

	public function onInit($param)
	{
		if($this->Request['id'] == 0 || $this->Request['id'] === '0')
		{
			$this->reportError(1,'profile_id_invalid',$id);
		}

		parent::onInit($param);
		
		$id = TPropertyValue::ensureInteger($this->Request['id']);

		if($id !== null)
		{
			if($this->User->RoleId != $this->Application->Parameters['AdminRole'] && $this->User->Id !== $id)
			{
				throw new PortalException(500,'profile_delte_disallowed',$id);
			}
		}
		else
		{
			$id	= $this->User->Id;
		}

		$this->_userRecord = $this->DataAccess->createCommand("select * from tblusers where id=$id")->queryRow();
		if($this->_userRecord === null)
		{
			throw new PortalException(500,'profile_id_invalid',$id);
		}
	}

	public function onLoad($param)
	{
		parent::onLoad($param);
		$this->Title = $this->Application->Parameters['SiteTitle'] . " - " . Prado::localize("Delete profile");
		if(!$this->IsPostBack)
		{
			$userRecord					= $this->_userRecord;
		}
	}

	public function deleteButtonClicked($sender,$param)
	{
		if($this->IsValid)
		{
			$userRecord = $this->_userRecord;
			$this->DataAccess->createCommand("delete from tblusers where id=" . $userRecord['id'])->execute();
			$this->Application->getModule('auth')->logout();
			$this->gotoPage($this->Service->DefaultPage);
		}
	}
}
?>